<?php

namespace App\Http\Controllers\Api;

use App\Coach;
use App\Video;
use Illuminate\Http\Request;

class VideoController extends BaseController
{
    public function list(Request $request)
    {
        $page = isset($request->page) ? $request->page : 1;
        $limit = isset($request->limit) ? $request->limit : 10;
        $sort = isset($request->sort) ? $request->sort : 'desc';
        $sortby = isset($request->sort) ? $request->limit : 'id';

        if (isset($request->status)) {
            $data = Video::with(['club:club_name'])
                ->where([
                    ['status', $request->status],
                ])
                ->orderBy($sortby, $sort)
                ->offset(($page - 1) * $limit)
                ->limit($limit)
                ->get();
        } else {
            $data = Video::with(['club:club_name'])
//        ->where([
//            ['status', $request->status],
//        ])
                ->orderBy($sortby, $sort)
                ->offset(($page - 1) * $limit)
                ->limit($limit)
                ->get();
        }


        return $this->apiResolveList($data, $page, $limit);
    }

    public function item(Request $request, Video $video)
    {
        return $this->apiResolveObject($video);
    }

}
